package cc.fs.zhihuapp.ui.activity.demo;

import android.os.Bundle;
import android.os.Message;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;

import java.net.URLEncoder;
import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cc.fs.zhihuapp.R;
import cc.fs.zhihuapp.model.VideoBean;
import cc.fs.zhihuapp.rest.asynchttp.VideoApi;
import cc.fs.zhihuapp.ui.activity.helper.BaseActivity;
import cc.fs.zhihuapp.ui.adapter.DataAdapter;
import cc.fs.zhihuapp.utils.MyCallback;

/**
 * Created by fostion on 2015/11/17.
 * 在电脑里面家里服务器，通过手机观看电脑里面的视频
 */
public class DataActivity extends BaseActivity {

    @InjectView(R.id.toolbar)
    Toolbar toolbar;
    @InjectView(R.id.recycler_view)
    RecyclerView recyclerView;

    LinearLayoutManager linearLayoutManager;
    DataAdapter dataAdapter;
    ArrayList<VideoBean> videos;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_data);
        ButterKnife.inject(this);

        toolbar.setTitle("VideoDeamo");

        setUpView();
    }

    private void setUpView() {
        videos = new ArrayList<>();
        dataAdapter = new DataAdapter(videos);
        recyclerView.setAdapter(dataAdapter);
        linearLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager);

        dataAdapter.setOnItemClickListener(new DataAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(VideoBean videoBean) {
//                VlcVideoActivity.start(_this,videoBean);
                String url = videoBean.getUrl().substring(0,videoBean.getUrl().lastIndexOf("/")+1)+ URLEncoder.encode(videoBean.getUrl().substring(videoBean.getUrl().lastIndexOf("/") + 1));
                VlcVideoActivity.start(_this, videoBean);
            }
        });

        VideoApi.getVideos(new MyCallback.NetworkCallback0<ArrayList<VideoBean>>() {
            @Override
            public void success(ArrayList<VideoBean> param) {
                videos.addAll(param);
                dataAdapter.notifyDataSetChanged();
            }

            @Override
            public void failure(String errror) {

            }
        });

    }


    @Override
    public void handler(Message msg) {

    }
}
